package com.atguigu.admin.user.controller;


import com.atguigu.admin.user.entity.User;
import com.atguigu.admin.user.service.UserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Durant
 * @since 2021-09-08
 */
@Controller
public class UserController {
    @Autowired
    UserService service;

    @RequestMapping("/dynamicTable")
    public String dynamicTable(@RequestParam(value = "pn",defaultValue = "1") Integer pn, HttpSession session, Model model) {
        IPage<User> ipage=new Page<>(pn,5);
        IPage<User> page = service.page(ipage);
        List<User> records = page.getRecords();
        Integer totalpage=(int)page.getPages();
        int[] pageNav = pageNAV.pageNav(pn, totalpage, 5);
        model.addAttribute("page", page);
        System.out.println(page.getTotal());
//        session.setAttribute("test", records);
        model.addAttribute("pagenum", pageNav);
//        model.addAttribute("users", records);
        return "dynamic_table";
    }
}

